package me.zhengjie.minbearwcs.dao.shifting.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.shifting.inf.ShiftingTaskRecordDao;
import me.zhengjie.minbearwcs.entity.Mapper.shifting.ShiftingTaskRecordMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.shifting.ShiftingTaskRecord;
import me.zhengjie.minbearwcs.entity.PO.wcs.shifting.status.ShiftingRecordStatus;
import org.springframework.stereotype.Repository;

@Repository
@RequiredArgsConstructor
public class ShiftingTaskRecordDaoImpl implements ShiftingTaskRecordDao {

    private final ShiftingTaskRecordMapper mapper;

    @Override
    public boolean insert(ShiftingTaskRecord shiftingTaskRecord) {
        return mapper.insert(shiftingTaskRecord) == 1;
    }

    @Override
    public ShiftingTaskRecord selectByRecordId(String recordId) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(ShiftingTaskRecord::getShiftingTaskRecordId, recordId)
                .oneOpt()
                .orElse(null);
    }

    @Override
    public boolean updateStatusByRecordId(String recordId, ShiftingRecordStatus status) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ShiftingTaskRecord::getShiftingTaskRecordId,recordId)
                .set(ShiftingTaskRecord::getStatus,status)
                .update();
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) == 1;
    }

    @Override
    public boolean updateEndPointByRecordId(String recordId, String endPoint) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(ShiftingTaskRecord::getShiftingTaskRecordId,recordId)
                .set(ShiftingTaskRecord::getEndPoint,endPoint)
                .update();
    }
}
